<script setup lang="ts">
import { reqGetKnowledgeList } from '@/services/consult'
import type {
  Knowledge,
  KnowledgeQueryType,
  KnowledgeType
} from '@/types/consult'
import KnowledgeCard from './KnowledgeCard.vue'
import { ref } from 'vue'
const list = ref<Knowledge[]>([])
const loading = ref(false)
const finished = ref(false)
const props = defineProps<{ type: KnowledgeType }>()
// 查询文章的数据
const queryType = ref<KnowledgeQueryType>({
  type: props.type,
  current: 1,
  pageSize: 2
})
const onLoad = async () => {
  // console.log(111)
  const res = await reqGetKnowledgeList(queryType.value)
  // console.log(res.data)
  // 存储文章列表数据
  list.value.push(...res.data.rows)
  // 关闭loading
  loading.value = false
  // 设置current递增
  queryType.value.current++
  if (queryType.value.current > res.data.pageTotal) {
    // 没有更多数据了
    finished.value = true
  }
}
</script>
<template>
  <div class="knowledge-list">
    <van-list
      v-model:loading="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <knowledge-card
        v-for="item in list"
        :key="item.id"
        :item="item"
      ></knowledge-card>
    </van-list>
  </div>
</template>

<style lang="scss" scoped>
.knowledge-list {
  padding: 0 15px;
}
</style>
